package edu.scau.finance.order.service;

import edu.scau.core.Enum.OrderStatus;
import edu.scau.finance.order.mapper.OrderReportMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class OrderReportServiceImpl implements OrderReportService{
    @Autowired
    private OrderReportMapper orderReportMapper;
    @Override
    public List<Map<String, Object>> getDailyOrderAmount(Date startTime, Date endTime,String period) {
        return orderReportMapper.getDailyOrderAmount(startTime,endTime,period);
    }

    @Override
    public List<Map<String,Object>> getOrderCountGroupedByStatus(Date startTime, Date endTime) {
        List<Map<String, Object>> rawList = orderReportMapper.getOrderCountGroupedByStatus(startTime, endTime);

        for (Map<String, Object> map : rawList) {
            int statusCode = ((Long) map.get("status")).intValue();
            String status = OrderStatus.getBySignal(statusCode).getDesc();
            map.put("status", status);  // 替换原来的status为中文
        }
        return rawList;
    }

    @Override
    public List<Map<String, Object>> calculateAmountGroupByCategory(Date startTime, Date endTime,String period) {
        return orderReportMapper.calculateAmountGroupByCategory(startTime,endTime,period);
    }
}
